package Class_Object.接口.demo2;
abstract class Animal {
    public String name;
    public int age;
    public Animal(String name,int age) {
        this.name = name;
        this.age = age;
    }
    public abstract void eat();

}
interface IFly {//TODO 设定某种特定功能的时候用接口
    void fly();
}
interface IRun {
    void run();
}
interface ISwim {
    void swim();

}
class Robot implements IRun {

    @Override
    public void run() {
        System.out.println("机器人正在用 机器腿跑步");
    }
}
class Dog extends Animal implements IRun {//TODO 狗是动物,具备 跑 的功能
    public Dog(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(this.name + "正在吃狗粮");
    }

    @Override
    public void run() {
        System.out.println(this.name + "正在用四条腿跑");
    }
}
class Frog extends Animal implements IRun,ISwim {
    public Frog(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(this.name + "正在吃虫子");

    }

    @Override
    public void run() {
        System.out.println(this.name + "正在用俩条腿跳着跑");
    }

    @Override
    public void swim() {
        System.out.println(this.name + "正在蛙泳");
    }
}
class Duck extends Animal implements IRun,ISwim,IFly {
//TODO alt + 回车可以快速生成
    public Duck(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(this.name + "正在吃鸭粮");

    }

    @Override
    public void fly() {
        System.out.println(this.name + "正在用翅膀飞");
    }

    @Override
    public void run() {
        System.out.println(this.name + "正在摇着屁股跑");

    }

    @Override
    public void swim() {
        System.out.println(this.name + "正在用脚板划着游泳");
    }
}
public class Test {
    public static void fuc(Animal animal) {
        animal.eat();
    }
    public static void run(IRun iRun) {
        iRun.run();
    }
    public static void fly(IFly ifly) {
        ifly.fly();
    }
    public static void swim(ISwim iSwim) {
        iSwim.swim();
    }

    public static void main2(String[] args) {
        run(new Dog("小白狗",17));
        run(new Frog("箭毒蛙",7));
        run(new Duck("唐老鸭",12));
        System.out.println("=====");
        fly(new Duck("唐老鸭",12));
        System.out.println("=====");
        run(new Robot());//只要具备跑这个功能都能用

    }
    public static void main(String[] args) {
        Animal animal = new Dog("小白狗",17);
        Animal animal1 = new Frog("箭毒蛙",7);
        Animal animal2 = new Duck("唐老鸭",12);

        fuc(animal);
        fuc(animal1);
        fuc(animal2);//或者直接在里面new


    }
}
